package com.zzedu.framework.interceptor;

import net.sf.jsqlparser.expression.Expression;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 数据权限上下文
 */
public class DataFilterScopeContext {

    public static final Logger log = LoggerFactory.getLogger(DataFilterScopeContext.class);

    private static final ThreadLocal<Expression> EXPRESSION_THREAD_LOCAL = new ThreadLocal<>();

    /**
     * 设置数据权限
     */
    public static void setDataFilterScope(Expression expression) {
        log.info("权限过滤where:{}", expression);
        EXPRESSION_THREAD_LOCAL.set(expression);
    }

    /**
     * 获得数据权限
     */
    public static Expression getDataFilterScope() {
        return EXPRESSION_THREAD_LOCAL.get();
    }

    /**
     * 清空数据权限
     */
    public static void clearDataFilterScope() {
        EXPRESSION_THREAD_LOCAL.remove();
    }
}
